package com.nyist.service.impl;

import java.util.List;
import java.util.UUID;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nyist.dao.ManageDao;
import com.nyist.entity.Manage;
import com.nyist.service.ManageService;

@Service("manageService")
public class ManageServiceImpl implements ManageService{
	@Autowired
	private ManageDao manageDao;
	public String addManage(Manage manage) {
		/**
		 * 由于存储数据需要进行转换，所以在这里我们需要从页面中获取的数据进行处理。
		 * ID 使用UUID 进行生产
		 */
		
		//ID 自动生成策略
		manage.setId(UUID.randomUUID().toString());
		//获得验证码
		String validateCode = manage.getValidatecode();
		String name = manage.getUsername();
		//生成新的密码
		String newpassword = manage.getPassword()+validateCode;
		//对密码进行加密
		String newpassword1 = DigestUtils.md5Hex(newpassword);
		
		manage.setPassword(newpassword1);
		manage.setUsername(name);
		manage.setValidatecode(validateCode);
		String mail = manage.getMail();
		manage.setMail(mail);
		manage.setState(0);
		System.out.println(manage);
		System.out.println("--------"+manageDao);
		manageDao.insert(manage);
		return manage.getId();
	}

	public void updateState(String id, String username) {
		manageDao.update(id, username);
		
	}

	public Manage queryForRegist(String username) {
		return manageDao.selectByUsername(username);
	}

	@Override
	public List<Manage> queryAllManage() {
		
		return manageDao.selectAll();
	}
	
}
